fish_cache_path(): simplify through use stack instead of heap
authorØyvind Kolås <pippin@gimp.org>
Sun, 20 Nov 2016 21:39:05 +0000 (22:39 +0100)
committerØyvind Kolås <pippin@gimp.org>
Sun, 20 Nov 2016 21:39:43 +0000 (22:39 +0100)
babl/babl-cache.c

index 0ef3f830bc797f24929c6f4d0946b907d08760af..e0c93656497feb20822ee4ba1031728a1b746010 100644 (file)
@@ -47,10 +47,12 @@ mk_ancestry_iter (const char *path)
 }
 
 static void
-mk_ancestry (char *path)
+mk_ancestry (const char *path)
 {
+  char copy[4096];
+  strncpy (copy, path, 4096);
 #ifdef _WIN32
-  for (char *c = path; *c; c++)
+  for (char *c = copy; *c; c++)
     if (*c == '\\')
       *c = '/';
 #endif
@@ -61,7 +63,6 @@ static const char *fish_cache_path (void)
 {
   struct stat stat_buf;
   static char resolved[4096];
-  char *ret = NULL;
 
 #ifndef _WIN32 
   if (getenv ("HOME"))
@@ -78,10 +79,7 @@ static const char *fish_cache_path (void)
   if (stat (resolved, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))
     return resolved;
 
-  ret = strdup (resolved);
-  mk_ancestry (ret);
-  strcpy (resolved, ret);
-  free (ret);
+  mk_ancestry (resolved);
 
   return resolved;
 }